
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<head>
		<title> CHATZZ2 </title>
		<link rel="stylesheet" type="text/css" href="../doc.css" />
		<meta charset="utf-8" />	
		<script language="JavaScript" type="text/JavaScript"> 	
				/*Text format*/
					function bold(){ 
					document.getElementById('message').style.fontWeight='bold';}
					function italics(){ 
					document.getElementById('message').style.fontStyle='italic';}
					function underlined(){ 
					document.getElementById('message').style.textDecoration = 'underline';}
		</script>
	</head>
	<body>
		<h1>DISCUSSION</h1>
		<div id="chatbox">
			<div id="online">
				<p> ONLINE </p>
				<?php
	
					$txt=stripslashes(file_get_contents("fichier.txt")); 	/*allows to print the oline user */
					echo nl2br(htmlspecialchars($txt));
					
				?>
			</div>	
			<?php
				session_start();
				$date = date('Y-m-d H:i:s');					/*We get back  date*/
				if(!empty($_POST['message']))
				{
												/*in the variable content_new we get back the line to add Packaging date, pseudo and message*/
				   $content_new = "<p>" .$date. "&nbsp<span>" .htmlspecialchars($_SESSION['username'])."</span>:&nbsp " .htmlspecialchars($_POST['message'])."</p>\n";
					$file = file("chat.txt");				 /*return the table file Packaging all line of chat.txt*/
																/*get back the ten last message*/
					for($i=0; $i<9; $i++)
					{ 
						$content_new .= $file[$i];
								
					}
					
					file_put_contents('chat.txt',($content_new));		/*put the contents of content_new in chat.txt */
				}			
			?>

			<div id="main">
				<?php
				//	echo stripslashes(file_get_contents("chat.txt")); /*allows to print the chat element */
				?>
			</div>
		
			<script src="../jquery.js"></script>
			<script type="text/javascript">
				function chat(){
					$.ajax({
						url:"chat.txt",   /*we give the path*/
						success:function(data){ /* test if open is Opening made a success and get back contents in data*/ 
						
							$("#main").empty().html(data);/*we get back name of "div" (#main) and print data's contents*/
						}
					});
					
				}
				setInterval("chat()",1000);
				chat();
			</script>
				
			<div id="messagebox">
				<form method="post"  action="" >
					
					<div id="left">
						
    <p><textarea name="message" id="message">Entrer votre message</textarea></p>
	<input value="G" type="button" onclick="javascript:bold()">&nbsp&nbsp
	<input value="I" type="button" onclick="javascript:italics())">&nbsp&nbsp
	<input  value="S" type="button" onclick="javascript:underlined()">&nbsp&nbsp
					</div>
					<div id="right">
						<input type="submit" value="send"/>
						<a href="deconexion.php"><input type="button" value="sign out" "/></a>
						
					</div>
				</form>
			</div>
			
		</div>
		
	</body>
</html>				